;(function() {
	'use strict';
	angular.module('controllers.oldOMDisplay.operationDevelop')
		.controller('odcOperationDevelopCtrl', odcOperationDevelopCtrl);

	function odcOperationDevelopCtrl($scope,odProblem,System,COREDATA,odOperationDevelop,$timeout,CoreService,sdsOperationDevelopService) {
		$scope.sendData = odProblem.sdsOperationDevelopService.getPageBind();
		$scope.timeTypes = odProblem.sdsOperationDevelopService.getTimeTypes();
		//控制查询条件拉上拉下   1为拉下  0 为拉上
		$scope.shoumun = {
			num: 1
		};
		//控制等待样式   false 为隐藏   true 为显示
		$scope._loading.show = false;
		$scope.showChannel = true;
		$scope.queryBusinessName = function(systemCode){
			if(systemCode === '22'){
				$scope.showChannel = false;
			}else {
				$scope.showChannel = true;
			}
			$scope.sendData.business = [];
			sdsOperationDevelopService.qeuryBuinessName({systemCode:systemCode},function(res){
				$scope.contents = res.data;
			});
		};
		$scope.init = function(){
			var send = {
				systemCode: $scope.sendData.system
			};
			sdsOperationDevelopService.qeuryBuinessName(send,function(res){
				$scope.contents = res.data;
			});
		};
		$scope.$watch('sendData.business',function(newValue){
			if($scope.sendData.business.length === 0){
				$scope.sendData.channel = [];
				$scope.channels = [{channelName:'天猫'},{channelName:'银行总对总'},{channelName:'移动商城'}];
			}
		});
		$scope.chooseBusChanel = function(code){
			$scope.sendData.channel = [];
			$timeout(function(){
				var codes = $scope.sendData.business.map(function(bus){
					return bus.businessCode;
				});
				if((codes.length === 1 && (codes.indexOf('02') !== -1 || codes.indexOf('03') !== -1)) || (codes.length !== 0 && codes.indexOf('01') === -1)){
					$scope.channels = [{channelName:'银行总对总'}];
				}else {
					$scope.channels = [{channelName:'天猫'},{channelName:'银行总对总'},{channelName:'移动商城'}];
				}
			});
		};
		var myEcharts = echarts.init(document.getElementById('doc'));
		$scope.search = function() {
			if ($scope.shoumun.num === 1) {
				$scope.shoumun.num = 1;
				return;
			}
			// return;
			$scope._loading.show = true;
			$scope.send = odOperationDevelop.fmtSendData($scope.sendData);
			var title = odOperationDevelop.getTitle($scope.send,'问题数');
			$scope.params = {};
			$scope.params.startTime = $scope.send.startTime;
			$scope.params.endTime = $scope.send.endTime;
			myEcharts.clear();
			odProblem.sdsOperationDevelopService.queryChannelProblem($scope.params, function(res) {
				if (res.state === '10000') {
					var myOption = odProblem.sdsOperationDevelopService.getEchartsData(res.data,title);
					myEcharts.setOption(myOption);

					$scope._loading.show = false;
					$scope.flag = 'view';
				}else if(res.data.length ===0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				}else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
		$scope.busContrast = function(){
			$scope._loading.show = true;
			var title ='';
			var systemName = '';
			$scope.send.systemName.length === 0 ? systemName = '' : systemName = $scope.send.systemName.toString();
			if($scope.send.startTime === $scope.send.endTime){
				title = systemName + $scope.send.startTime.replace(/-/g,'')+'各业务问题数对比';
			}else {
				title = systemName + $scope.send.startTime.replace(/-/g,'')+'_'+$scope.send.endTime.replace(/-/g,'')+'各业务问题数对比';
			}
			myEcharts.clear();
			odProblem.sdsOperationDevelopService.queryBusinessProblems($scope.params,function(res){
				if (res.state === '10000') {
					var myOption = odOperationDevelop.getEchartsData(res.data,title,'time','businessName','problemCount','bar');
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
				}else if(res.data.length ===0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				}else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
		$scope.channelContrast = function(){
			$scope._loading.show = true;
			var title = odOperationDevelop.getTitle($scope.send,'问题数对比');
			myEcharts.clear();
			odProblem.sdsOperationDevelopService.queryChannelProblems($scope.params,function(res){
				if (res.state === '10000') {
					var myOption = odOperationDevelop.getEchartsData(res.data,title,'time','channelName','problemCount','bar');
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
				}else if(res.data.length ===0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				}else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
	}
	odcOperationDevelopCtrl.$inject = ['$scope','odProblem','System','COREDATA','odOperationDevelop','$timeout','CoreService','sdsOperationDevelopService'];
})();